﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using IronOne.SalesOne.BusinessObjects;

namespace IronOne.SalesOne.SalesOneWeb.UserManagement
{

    public partial class CreateUserType : SOSecurityPage
    {
        Facade.StructureFacade structureFacade = new Facade.StructureFacade();
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidateUserCredentials(Request.Url.LocalPath);
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            string strUserTypeName = txtUserTypeName.Text;

            if (structureFacade.GetUserTypeByName(strUserTypeName).Count < 1)
            {
                UserType userType = new UserType();

                userType.UserTypeName = strUserTypeName;
                userType.LoweredUserTypeName = strUserTypeName.ToLower();
                userType.Description = txtDescription.Text;

                structureFacade.InsertUserType(userType);
            }
            else
            {
                Response.Write("User type already exists.");
            }
            
        }
    }
}
